package com.yj.exception;

/**
 * @author sunweiwei
 * @date 2018/10/25
 */
public class BusinessException extends RuntimeException {
    private String errorMessage;
    private BaseExceptionEnums exceptionEnums;
    private String errorCode = "UNKNOWN_ERROR";

    public BusinessException(String errorMessage) {
        super(errorMessage);
        this.errorMessage = errorMessage;
    }

    public BusinessException(BaseExceptionEnums exceptionEnums) {
        this.exceptionEnums = exceptionEnums;
        this.errorCode = exceptionEnums.getCode();
        this.errorMessage = exceptionEnums.getMessage();
    }

    @Override
    public String getMessage() {
        if (this.errorMessage != null) {
            return this.errorMessage;
        } else {
            return super.getMessage() != null ? super.getMessage() : this.errorMessage;
        }
    }

    public String getErrorCode() {
        return this.errorCode;
    }

    public BaseExceptionEnums getExceptionEnums() {
        return this.exceptionEnums;
    }
}
